﻿using FinalYear.Helpers;
using System;
using System.Collections.Generic;

namespace FinalYear.OpticalFlow.Classes
{
    /// <summary>
    /// Class that is used to store the historical data of a
    /// perspective collision, this stores the value of the center collision
    /// </summary>
    public class CollisionHistogram
    {
        public DateTime CurrentCollisionTime { get; set; }

        public DateTime PreviousCollisionTime { get; set; }

        public List<float> CumulativeCollision { get; set; }

        public bool SonarCollision { get; set; }

        public string SonarCollisionDistance { get; set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="CollisionHistogram" /> class.
        /// </summary>
        public CollisionHistogram()
        {
            this.PreviousCollisionTime = DateTime.MinValue;
            this.CurrentCollisionTime = DateTime.MinValue;
            this.SonarCollisionDistance = string.Empty;
            this.SonarCollision = false;

            if (this.CumulativeCollision == null)
            {
                this.CumulativeCollision = new List<float>();
            }
        }

        public bool CheckTimeBetweenCollisions()
        {
            if (CurrentCollisionTime != DateTime.MinValue)
            {
                TimeSpan timeDifference = this.CurrentCollisionTime - this.PreviousCollisionTime;

                if (timeDifference.TotalSeconds > Constants.TIMEBETWEENCOLLSIONS)
                {
                    return true;
                }
            }

            return false;
        }
    }
}